// pages/mine/collect/collect.js
import { HTTP } from '../../../utils/http.js'
let ajax = new HTTP()
const app = getApp()
Page({
    data: {
        currentTab: 0,
        winHeight: "",
        collectTitle: [{
                text: '直播',
                id: 0
            },
            {
                text: '培训',
                id: 1
            },
            {
                text: '视频',
                id: 2
            }
        ],
        collectLive: [],
        collectTrain: [],
        collectVideo: [],
        loading: false
    },
    onLoad(options) {
        wx.showLoading({
            title: '加载中',
        })
        wx.getSystemInfo({
            success: (res) => {
                let clientHeight = res.windowHeight
                let clienWidth = res.windowWidth
                let rpxR = 750 / clienWidth
                let calc = clientHeight * rpxR
                this.setData({
                    winHeight: calc - 95
                })
                let memberid = app.globalData.memberid
                this._getMycollectList(memberid, 1)
                this._getMycollectList(memberid, 3)
                this._getMycollectList(memberid, 4)
            },
        })
    },
    // 点击列表
    switchNav(event) {
        let cur = event.currentTarget.dataset.current
        if (this.data.currentTab === cur) {
            return false
        } else {
            this.setData({
                currentTab: cur
            })
        }
    },
    // 左右滑动
    switchTab(event) {
        this.setData({
            currentTab: event.detail.current
        })
    },
    _getMycollectList(memberid, reltype) {
        ajax.request({
            method: "GET",
            url: "mycenter",
            data: {
                actname: 'myfavor',
                memberid: memberid,
                reltype: reltype
            },
            success: (res) => {
                wx.hideLoading()
                if (res.rescode == "0000") {
                    if (reltype == 1) {
                        this.setData({
                            collectLive: res.data,
                            loading: true
                        })
                    } else if (reltype == 3) {
                        this.setData({
                            collectTrain: res.data
                        })
                    } else if (reltype == 4) {
                        this.setData({
                            collectVideo: res.data
                        })
                    }
                }
            }
        })
    },
    onVideoTap(event) {
        let reltype = event.currentTarget.dataset.posttype
        let postId = event.currentTarget.dataset.postid
        let postTitle = event.currentTarget.dataset.posttitle
        console.log(reltype, postId, postTitle)
        if (reltype == 1) {
            let hasLive = event.currentTarget.dataset.hasive;
            if (hasLive == 1) {
                wx.navigateTo({
                    url: '/pages/live/detail/detail?id=' + postId + '&title=' + postTitle,
                })
            } else {
                wx.navigateTo({
                    url: '/pages/live/record/record?id=' + postId + '&title=' + postTitle,
                })
            }
        } else if (reltype == 3) {
            wx.navigateTo({
                url: '/pages/find/fitness/detail/detail?id=' + postId + '&title=' + postTitle,
            })
        } else if (reltype == 4) {
            wx.navigateTo({
                url: '/pages/find/vision/detail/detail?id=' + postId + '&title=' + postTitle,
            })
        }
    }
})